package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseCategoryTrademark;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.CategoryTrademarkVo;
import com.atguigu.gmall.product.service.BaseCategoryTradeMarkService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseCategoryTrademark")
public class BaseCategoryTradeMarkController {
    @Autowired
    private BaseCategoryTradeMarkService baseCategoryTradeMarkService;

    /**
     * 根据category3Id获取品牌列表
     * @param category3Id
     * @return
     */
    @GetMapping("/findTrademarkList/{category3Id}")
    public Result findTrademarkList(@PathVariable Long category3Id) {
        List<BaseTrademark> baseCategoryTrademarkList = baseCategoryTradeMarkService.getTrademarkList(category3Id);
        return Result.ok(baseCategoryTrademarkList);
    }

    /**
     * 根据category3Id获取可选品牌列表
     * @param category3Id
     * @return
     */
    @GetMapping("/findCurrentTrademarkList/{category3Id}")
    public Result findCurrentTrademarkList(@PathVariable Long category3Id) {
        List<BaseTrademark> baseCategoryTrademarkList = baseCategoryTradeMarkService.getCurrentTrademarkList(category3Id);
        return Result.ok(baseCategoryTrademarkList);
    }

    /**
     * 保存分类品牌关联
     * @param categoryTrademarkVo
     * @return
     */
    @PostMapping("/save")
    public Result saveBaseCategoryTradeMark(@RequestBody CategoryTrademarkVo categoryTrademarkVo) {
        baseCategoryTradeMarkService.saveBaseCategoryTradeMark(categoryTrademarkVo);
        return Result.ok();
    }
    /**
     *
     * @param category3Id
     * @param trademarkId
     * @return
     */
    @DeleteMapping("/remove/{category3Id}/{trademarkId}")
    public Result remove(@PathVariable Long category3Id, @PathVariable Long trademarkId) {
        LambdaQueryWrapper<BaseCategoryTrademark> baseCategoryTrademarkLambdaQueryWrapper = new LambdaQueryWrapper<>();
        baseCategoryTrademarkLambdaQueryWrapper.eq(BaseCategoryTrademark::getCategory3Id, category3Id);
        baseCategoryTrademarkLambdaQueryWrapper.eq(BaseCategoryTrademark::getTrademarkId, trademarkId);
        baseCategoryTradeMarkService.remove(baseCategoryTrademarkLambdaQueryWrapper);
        return Result.ok();
    }
}
